<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class topuser_class extends CI_Model {
	
		
		public function list_topuser(){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->order_by("intPoints", "Desc");
				$query = $this->db->get_where('jtn_users_points',array('intDisabled'=>0,'intID'=>$intID,'intPointsID'=>1));
			} else {
				$this->db->order_by("intPoints", "Desc");
				$query = $this->db->get_where('jtn_users_points',array('intDisabled'=>0,'intPointsID'=>1));
			}
			if ($query->num_rows() > 0){
				$result = $query->result_array();
				return $result;
			}
			else{
				return 0;
			}
		}	
		/*
			Get User Points
		*/
		public function get_user_points($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intUserID'=>$intID));
			}
			if(isset($post['intPointType'])){
				$intPointType = stripslashes(filter_var($post['intPointType'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intPointsID'=>$intPointType));
			}
			$query = $this->db->get('jtn_users_points')->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function update_user_points($post){
			$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
			$intPointsID = stripslashes(filter_var($post['intPointsID'], FILTER_SANITIZE_STRING));
			$intPoints = stripslashes(filter_var($post['intPoints'], FILTER_SANITIZE_STRING));
			
			$data = array(
					'intPoints'=>$intPoints,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			$this->db->where(array('intUserID'=>$intUserID,'intPointsID'=>$intPointsID));
			$this->db->update('jtn_users_points',$data);
			
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully updated.";
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();
			}
			return $message;
		}
	} // end class
?>